//
//  Stack.m
//  SCRAP_ObjC
//
//  Created by SRL on 10/26/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "Stack.h"


@implementation Stack
@synthesize cards, suit, size;

-(BOOL)isValid:(Card*) c
{
	//return TRUE;
	if(c == nil)
		return FALSE;
	int rank = [cards count];
//	NSLog(@"Card r:%d s:%c Stack r:%d s:%c", c.rank, c.suit, rank, suit);
	if(c.suit != suit)
	{
		return FALSE;
	}
	if ([cards count] == 0 && c.rank == 1) {
		return TRUE;
	}
	else if(rank == c.rank -1)
	{
		return TRUE;
	}
	
	return FALSE;
}

-(BOOL)addCard:(Card*) c
{
	if([self isValid:c])
	{
		[cards push:c];
		return TRUE;
	}
	return FALSE;
}

+(id) initWithSuit:(char)s withRotation:(float)r
{
//	Stack *stack = [Stack node];
	NSString* loadString = @"heart_ipad2.png";
	switch(s)
	{
		case 's': loadString = @"spades_ipad2.png";
			break;
		case 'd': loadString = @"diamond_ipad2.png";
			break;
		case 'c': loadString = @"club_ipad2.png";
			break;
		default:break;
	}
	Stack *stack = [Stack spriteWithFile:loadString];
	stack.rotation = r;
	
	stack.opacity = 225;
//	Stack *stack = (Stack*)[CCSprite spriteWithFile:@"stackglow.png"];
	stack.cards = [[NSMutableArray alloc] init];
	[stack setScale:iPadScale];
	stack.suit = s;
	return stack;

}

-(void) dealloc
{
	[super dealloc];
}


@end
